from bsta import word_freq
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
from os import path

import matplotlib.image as mpig


def wc_create(text,name):
    mask = mpig.imread("png/siye.jpeg")
    font_path = path.join("font/msyh.ttf")
    stopwords = set(STOPWORDS)
    wordcloud = WordCloud(font_path=font_path,
                          stopwords=stopwords,
                          background_color="white",
                          # mask=mask,
                          width=4000,
                          height=2000,
                          margin=10,
                          )
    resdic = word_freq(text, 50, 1)
    wordcloud.fit_words(resdic)
    wordcloud.to_file("result/3.png")
    plt.imshow(wordcloud)
    # 显示
    plt.axis("off")  # 关掉图像的坐标

    plt.show()


name = '1'
with open('doc/'+name+".txt", 'r', encoding='UTF-8') as f:
    text = f.read()
    f.close()

wc_create(text,name)


